package com.bcu.calculus.controller;

import com.bcu.calculus.entity.Message;
import com.bcu.calculus.entity.User;
import com.bcu.calculus.entity.UserNumber;
import com.bcu.calculus.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "11  用户模块")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "用户登录")
    @PostMapping(value = "/login")
    public Message<User> userLogin(User user){
        return userService.Login(user.getUserId(),user.getUserPwd());
    }


    @ApiOperation(value = "用户添加")
    @PostMapping(value = "/addUser")
    public Message<?> addUser(User user){
        return userService.addUser(user);
    }

    @ApiOperation(value = "通过主键查询单个用户")
    @GetMapping(value = "/findOne")
    public Message<UserNumber> findOne(String userId){
        return userService.findUserByPrimaryKey(userId);
    }

    @ApiOperation(value = "查找单个用户以及信息")
    @GetMapping(value = "/findOneAndInfo")
    public Message<User> findOneUserByPrimaryKey(String userId){
        return userService.findUserAndInfoByPrimaryKey(userId);
    }

    @ApiOperation(value = "查找所有用户")
    @GetMapping(value = "/getAll")
    public Message<List<User>> findAllUsers(){
        return userService.findAllUser();
    }

    @ApiOperation(value = "查找所有的用户以及信息")
    @GetMapping(value = "/findAllInfo")
    public Message<List<User>> getAllUserAndInfo(){
        return userService.findAllUserAndUserInfo();
    }

    @ApiOperation(value = "通过主键删除用户")
    @DeleteMapping(value = "/delone")
    public Message<?> delUser(String userId){
        return userService.delUser(userId);
    }

    @ApiOperation(value = "更新用户")
    @PostMapping(value = "/update")
    public Message<?> updateUser(User user) {
        return userService.updateUserByPrimaryKeySelective(user);
    }

    @ApiOperation(value = "注销")
    @PostMapping(value = "/logout")
    public Message logout()
    {
        return Message.success("注销成功");
    }



    /*
    @ApiOperation(value = "获取所有人的排名")
    @GetMapping(value = "/getallranking")
    public  Message<List<User>> getAllRanking(){
        return userService.findAllUserAndUserInfo();
    }

    @ApiOperation(value = "获取党小组排名")
    @GetMapping(value = "/getrankingbybranch")
    public  Message<List<User>> getRankingByBranch(Integer branch){
        return userService.getAllUserRankInBranch(branch);
    }



    @ApiOperation(value = "获取某个具体用户在当下组内的排名")
    @GetMapping(value = "/getOneRankingInBranch")
    public Message<Integer> getOneRankingInBranch(String userId, Integer branch){
        return userService.getOneUserRankInBranch(userId,branch);
    }


    @ApiOperation(value = "获取某个具体用户的排名")
    @GetMapping(value = "/getOneRanking")
    public Message<Integer> getOneRanking(String userId){
        return userService.getOneUserRank(userId);
    }

     */

    @ApiOperation(value = "根据用户权限获取不同等级的所有路由")
    @GetMapping(value = "/getListsByUserType")
    public Message getListsByUserType(String userType){
        return userService.getListByUserType(userType);
    }

}
